<!doctype html>
<html lang="en-US">
  <head>
    <title>Link Definition Badge: Test link definition badge</title>
    <link href="/assets/index.css" rel="stylesheet" type="text/css" />
    <script type="importmap">
      {
        "imports": {
          "react": "https://esm.sh/react@18.3.1",
          "react-dom": "https://esm.sh/react-dom@18.3.1",
          "react-dom/": "https://esm.sh/react-dom@18.3.1/",
          "@fluentui/react-components": "https://esm.sh/@fluentui/react-components?deps=react@18.3.1&exports=FluentProvider,createDarkTheme,webLightTheme"
        }
      }
    </script>
    <script crossorigin="anonymous" src="/test-harness.js"></script>
    <script crossorigin="anonymous" src="/test-page-object.js"></script>
    <script type="module">
      import React from 'react';
      window.React = React;
    </script>
    <script defer crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
    <script defer crossorigin="anonymous" src="/__dist__/botframework-webchat-fluent-theme.production.min.js"></script>
    <style type="text/css">
      .fui-FluentProvider {
        height: 100%;
      }
    </style>
  </head>
  <body>
    <main id="webchat"></main>
    <script type="module">
      import React from 'react';
      import { createRoot } from 'react-dom/client';
      import { FluentProvider, createDarkTheme, webLightTheme } from '@fluentui/react-components';

      run(async function () {
        const {
          WebChat: { FluentThemeProvider, ReactWebChat }
        } = window;

        const { directLine, store } = testHelpers.createDirectLineEmulator();

        const searchParams = new URLSearchParams(location.search);
        const variant = searchParams.get('variant');
        const theme = searchParams.get('fluent-theme');

        await host.sendDevToolsCommand('Emulation.setEmulatedMedia', {
          features: [
            { name: 'prefers-reduced-motion', value: 'reduce' },
            ...(theme === 'dark' || theme === 'light'
              ? [{ name: 'prefers-color-scheme', value: theme }]
              : [])
          ]
        });

        const root = createRoot(document.getElementById('webchat'));

        let fluentTheme;

        if (theme === 'dark' || window.matchMedia('(prefers-color-scheme: dark)').matches) {
          fluentTheme = {
            ...createDarkTheme({
              10: '#12174c',
              20: '#1a1f5b',
              30: '#21276a',
              40: '#293079',
              50: '#303788',
              60: '#384097',
              70: '#4049a7',
              80: '#151e80',
              90: '#4f59c5',
              100: '#5661d4',
              110: '#5e69e3',
              120: '#7982e8',
              130: '#949bec',
              140: '#afb5f1',
              150: '#c9cdf6',
              160: '#e4e6fa'
            }),
            colorNeutralBackground1Disabled: '#101010',
            colorNeutralBackground1Hover: '#101010',
            colorNeutralForeground5: '#424242'
          };
        } else {
          fluentTheme = {
            ...webLightTheme,
            // Original is #242424 which is too light for fui-FluentProvider to pass our a11y
            colorNeutralForeground1: '#1b1b1b',
          };
        }

        const webChatProps = { dir: searchParams.get('dir'), directLine, store };

        root.render(
          variant ? 
            React.createElement(
              FluentProvider,
              { className: 'fui-FluentProvider', theme: fluentTheme },
              React.createElement(
                FluentThemeProvider,
                { variant: variant },
                React.createElement(ReactWebChat, webChatProps)
              )
            ) :
            React.createElement(ReactWebChat, webChatProps)
        );

        await pageConditions.uiConnected();

        await directLine.emulateIncomingActivity({
          entities: [
            {
              '@context': 'https://schema.org',
              '@id': '',
              '@type': 'Message',
              citation: [
                {
                  '@type': 'Claim',
                  appearance: {
                    '@type': 'DigitalDocument',
                    url: 'https://example.com/1/',
                    usageInfo: {
                      '@id': '_:1',
                      '@type': 'CreativeWork',
                      description:
                        'Nisi quis ut sint elit est nulla enim eiusmod. Deserunt commodo pariatur nostrud culpa aliquip esse pariatur exercitation nulla do proident. Est qui eiusmod aliquip deserunt labore consequat fugiat. Ullamco reprehenderit nostrud eiusmod nisi nulla esse id. Reprehenderit aliqua quis consectetur sit cupidatat fugiat Lorem ex labore. Eiusmod velit laborum quis tempor incididunt excepteur culpa esse nulla.',
                      keywords: ['encrypted-content'],
                      name: 'Sit veniam do irure velit est et quis ut Lorem reprehenderit commodo cillum occaecat',
                      pattern: {
                        '@type': 'DefinedTerm',
                        inDefinedTermSet: 'https://www.w3.org/TR/css-color-4/',
                        name: 'color',
                        termCode: 'orange'
                      }
                    }
                  },
                  position: 1
                },
                {
                  '@type': 'Claim',
                  appearance: {
                    '@type': 'DigitalDocument',
                    text: 'Incididunt amet dolore anim commodo fugiat occaecat elit nulla do consequat. Quis incididunt occaecat labore adipisicing. Cillum sunt velit consequat irure ipsum ullamco sint ea aute. Sunt et eu ut enim aliqua cupidatat non adipisicing dolore commodo dolor magna enim. Commodo reprehenderit excepteur ad nostrud ex id aliquip deserunt eiusmod. Esse non labore nulla voluptate.',
                    usageInfo: {
                      '@type': 'CreativeWork',
                      name: 'Velit exercitation',
                      pattern: {
                        '@type': 'DefinedTerm',
                        inDefinedTermSet: 'https://www.w3.org/TR/css-color-4/',
                        name: 'color',
                        termCode: 'Yellow'
                      }
                    }
                  },
                  position: 3
                },
                {
                  '@type': 'Claim',
                  appearance: {
                    '@type': 'DigitalDocument',
                    text: 'Ea nisi nostrud duis dolore aliqua sit reprehenderit minim est nisi id est sit. Amet mollit ex fugiat sint aliquip Lorem eiusmod incididunt nulla laboris labore nulla. In id exercitation ut non non Lorem consequat cupidatat deserunt do aliqua exercitation. Minim commodo aliquip dolore exercitation officia commodo sint aute aute. Fugiat laborum proident cupidatat quis eiusmod excepteur voluptate commodo. Ullamco minim duis id deserunt laboris ullamco cupidatat dolor est sint ut. Anim pariatur non ea do occaecat dolor sint ad.'
                  },
                  position: 4
                }
              ],
              type: 'https://schema.org/Message',
              usageInfo: { '@id': '_:1' },
              author: {
                '@type': 'Person',
                name: 'Lorem Ipsum Expert'
              }
            }
          ],
          text: 'Ipsum[1] dolore[2] cupidatat[3] magna[4] consectetur[5] do tempor est excepteur.\n\n[1]: https://example.com/1/ "Sint amet id officia dolor ex eiusmod ipsum ipsum magna fugiat"\n[2]: https://example.com/2/ "Laboris cupidatat voluptate"\n[3]: _:3 "Velit nulla culpa eu ea consectetur consectetur dolore velit"\n[4]: _:4 "Adipisicing enim nulla"\n[5]: https://example.com/5',
          type: 'message'
        });

        await host.snapshot('local');

        const [firstActivityElement] = pageElements.activities();

        const linkDefinitions = firstActivityElement.querySelectorAll('.webchat__link-definitions__list-item');

        expect(linkDefinitions).toHaveProperty('length', 5);

        expect(linkDefinitions[0].querySelector('.webchat__link-definitions__list-item-box').tagName).toBe('A');
        expect(
          linkDefinitions[0].querySelector('.webchat__link-definitions__list-item-text').getAttribute('title')
        ).toBe('Sint amet id officia dolor ex eiusmod ipsum ipsum magna fugiat');
        expect(
          linkDefinitions[0].querySelector('.webchat__link-definitions__list-item-badge').getAttribute('title')
        ).toBe(
          'Sit veniam do irure velit est et quis ut Lorem reprehenderit commodo cillum occaecat\n\nNisi quis ut sint elit est nulla enim eiusmod. Deserunt commodo pariatur nostrud culpa aliquip esse pariatur exercitation nulla do proident. Est qui eiusmod aliquip deserunt labore consequat fugiat. Ullamco reprehenderit nostrud eiusmod nisi nulla esse id. Reprehenderit aliqua quis consectetur sit cupidatat fugiat Lorem ex labore. Eiusmod velit laborum quis tempor incididunt excepteur culpa esse nulla.'
        );

        expect(linkDefinitions[1].querySelector('.webchat__link-definitions__list-item-box').tagName).toBe('A');
        expect(
          linkDefinitions[1].querySelector('.webchat__link-definitions__list-item-text').getAttribute('title')
        ).toBe('Laboris cupidatat voluptate');
        expect(linkDefinitions[1].querySelector('.webchat__link-definitions__list-item-badge')).toBeNull();

        expect(linkDefinitions[2].querySelector('.webchat__link-definitions__list-item-box').tagName).toBe('BUTTON');
        expect(
          linkDefinitions[2].querySelector('.webchat__link-definitions__list-item-text').getAttribute('title')
        ).toBe('Velit nulla culpa eu ea consectetur consectetur dolore velit');
        expect(
          linkDefinitions[2].querySelector('.webchat__link-definitions__list-item-badge').getAttribute('title')
        ).toBe('Velit exercitation');

        expect(linkDefinitions[3].querySelector('.webchat__link-definitions__list-item-box').tagName).toBe('BUTTON');
        expect(
          linkDefinitions[3].querySelector('.webchat__link-definitions__list-item-text').getAttribute('title')
        ).toBe('Adipisicing enim nulla');
        expect(linkDefinitions[3].querySelector('.webchat__link-definitions__list-item-badge')).toBeNull();

        expect(document.querySelector('.webchat__link-definitions__header-text')).toHaveProperty(
          'textContent',
          '5 references'
        );

        expect(document.querySelector('.webchat__link-definitions__message-sensitivity-label-text')).toHaveProperty(
          'textContent',
          'Sit veniam do irure velit est et quis ut Lorem reprehenderit commodo cillum occaecat'
        );

        expect(document.querySelector('.webchat__link-definitions__message-sensitivity-label')).toHaveProperty(
          'title',
          'Sit veniam do irure velit est et quis ut Lorem reprehenderit commodo cillum occaecat\n\nNisi quis ut sint elit est nulla enim eiusmod. Deserunt commodo pariatur nostrud culpa aliquip esse pariatur exercitation nulla do proident. Est qui eiusmod aliquip deserunt labore consequat fugiat. Ullamco reprehenderit nostrud eiusmod nisi nulla esse id. Reprehenderit aliqua quis consectetur sit cupidatat fugiat Lorem ex labore. Eiusmod velit laborum quis tempor incididunt excepteur culpa esse nulla.'
        );

        expect(
          document.querySelector('.webchat__link-definitions__message-sensitivity-label--is-encrypted')
        ).toBeTruthy();
      });
    </script>
  </body>
</html>
